package com.laze.mywanandroid.ui.main.fragment.project

import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.laze.mywanandroid.R
import com.laze.mywanandroid.bean.Project

class ProjectListAdapter (layoutId:Int) : BaseQuickAdapter<Project, BaseViewHolder>(layoutId),LoadMoreModule{
    override fun convert(holder: BaseViewHolder, item: Project) {
        Glide.with(context).load(item.envelopePic).into(holder.getView(R.id.imageProject))
        holder.setText(R.id.tvProjectTitle,item.title)
            .setText(R.id.tvProjectContent,item.desc)
            .setText(R.id.tvProjectTime,item.niceDate)
            .setText(R.id.tvProjectAuthor,item.author)
        //初始化，防止item图标复用错乱
        holder.getView<ImageView>(R.id.imageProjectCollect).drawable.setTint(ContextCompat.getColor(context,R.color.collectColorDefault))
        if (item.collect){
            holder.getView<ImageView>(R.id.imageProjectCollect).drawable.setTint(ContextCompat.getColor(context,R.color.collectColorStar))
        }else{
            holder.getView<ImageView>(R.id.imageProjectCollect).drawable.setTint(ContextCompat.getColor(context,R.color.collectColorDefault))
        }
    }
}